package edu.gatech.bsbmule.view;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import edu.gatech.bsbmule.model.CustomizedTimer;
import edu.gatech.bsbmule.model.Game;
import edu.gatech.bsbmule.model.Player;
import edu.gatech.bsbmule.model.Pub;


/**
 * Creates the Pub screen with "Gamble" button. 
 * Prints player winnings and updated money to the console.
 * 
 * @author Melissa
 * @version 1.0 10/20/13
 */
public class PubScreen extends JPanel {
	public PubScreen() {
		
		setBorder(new EmptyBorder(20,20,20,20));
		setLayout(new GridLayout(3, 3, 10, 10));
		
		JButton btnNewButton = new JButton("Gamble (This will end your turn!)");
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//Add the money
				Pub pub = new Pub();
				int moneyGained = pub.calculateBonus();
				Player currentPlayer = Game.getInstance().getCurrentPlayer();
				currentPlayer.addMoney(moneyGained);
				
				System.out.println(currentPlayer.getName() + " won " + 
						moneyGained + " in the pub.");
				System.out.println("Money after gambling: " + 
						currentPlayer.getMoney());
				
				//Get to the next player
				TownWindow.getInstance().setTitle("The Town");
				TownWindow.getInstance().dispose();
				CustomizedTimer.getInstance().byPass();
			}
		});
		add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Return");
		btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 24));
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TownWindow.getInstance().setTitle("The Town");
				TownWindow.getInstance().setPanel(TownScreen.getInstance());
			}
		});
		add(btnNewButton_1);
	}
}
